﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;

public partial class Controls_PopProduct : System.Web.UI.UserControl
{
	private ProductManager m_ProductManager		= new ProductManager();

    public string CategoryId { get; set; }
    public string CategoryName { get; set; }

    private string m_imageSrc = "../imagesWeb/num01.gif";
    public string ImageSrc
    {
        get { return m_imageSrc; }
        set { m_imageSrc = value; }
    }

	private int m_ShowCount = 5; 
	public int ShowCount
	{
		get { return m_ShowCount; }
		set { m_ShowCount = value; }
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			this.BindProduct();
		}
	}

	private void BindProduct()
	{
        this.lvProduct.DataSource = this.m_ProductManager.GetAll_L().OrderByDescending(theProduct => theProduct.Views).Take(ShowCount).ToList();
        this.lvProduct.DataBind();
        //if (!string.IsNullOrEmpty(CategoryId) && !string.IsNullOrEmpty(CategoryName))
        //{
        //    this.lvProduct.DataSource = this.m_ProductManager.GetAll().OrderByDescending(theProduct => theProduct.Views).Take(ShowCount).ToList();
        //    this.lvProduct.DataBind();
        //}
        //else if (string.IsNullOrEmpty(CategoryId) && !string.IsNullOrEmpty(CategoryName))
        //{
        //    this.lvProduct.DataSource = null;
        //    this.lvProduct.DataBind();
        //}
        //else if (!string.IsNullOrEmpty(CategoryId) && string.IsNullOrEmpty(CategoryName))
        //{
        //    this.lvProduct.DataSource = null;
        //    this.lvProduct.DataBind();
        //}
	}

    protected void lvProduct_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        int i = 1;  
        HtmlImage img = e.Item.FindControl("imgNum") as HtmlImage;

        if (img != null)
        {
            img.Src = "../imagesWeb/num0"+(Convert.ToInt16(e.Item.ID.Substring(4))+1).ToString()+".gif"; ;
        }
        
    }
  
}
